package com.example.agriapp.util;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

public class ImageLoader {
    private static final RequestOptions DEFAULT_OPTIONS = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .centerCrop()
            .dontAnimate();

    public static void load(Context context, String url, ImageView imageView) {
        Glide.with(context)
                .load(url)
                .apply(DEFAULT_OPTIONS)
                .into(imageView);
    }

    public static void loadWithPlaceholder(Context context, String url, ImageView imageView, int placeholderResId) {
        Glide.with(context)
                .load(url)
                .apply(DEFAULT_OPTIONS.placeholder(placeholderResId))
                .into(imageView);
    }

    public static void loadCircle(Context context, String url, ImageView imageView) {
        Glide.with(context)
                .load(url)
                .apply(DEFAULT_OPTIONS.circleCrop())
                .into(imageView);
    }

    public static void loadCircleWithPlaceholder(Context context, String url, ImageView imageView, int placeholderResId) {
        Glide.with(context)
                .load(url)
                .apply(DEFAULT_OPTIONS.circleCrop().placeholder(placeholderResId))
                .into(imageView);
    }

    public static void clear(Context context, ImageView imageView) {
        Glide.with(context).clear(imageView);
    }
}